package com.hzdl.flower.controller;

import com.github.pagehelper.PageInfo;
import com.hzdl.flower.bean.Log;
import com.hzdl.flower.service.LogService;
import com.hzdl.flower.util.HZDLJsonResult;
import com.hzdl.flower.vo.AdminVo;
import com.hzdl.flower.vo.LogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("log")
public class LogController {
    @Autowired
    private LogService ls;

    @RequestMapping("logInit")
    private String logInit(){
        return "admin/log" ;
    }

    @ResponseBody
    @RequestMapping("findLog")
    public HZDLJsonResult findLog(LogVo logVo){
        PageInfo p = ls.findLog(logVo);
        return new HZDLJsonResult(0,"",p.getTotal(), p.getList());
    }

    @RequestMapping("checkExitChildren")
    @ResponseBody
    public HZDLJsonResult checkExitChildren(LogVo logVo){
        Log log =  ls.findByid(logVo.getId());
        return new HZDLJsonResult(0,"",log);
    }


    @RequestMapping("deletelog")
    @ResponseBody
    public HZDLJsonResult deletelog(Integer id){
        int row = ls.deleteById(id);
        if (row == 0){
            return HZDLJsonResult.DELETE_ERROR;
        }else {
            return HZDLJsonResult.DELETE_SUCCESS;
        }
    }

    @ResponseBody
    @RequestMapping("delAll")
    public HZDLJsonResult deAll(String ids){
        String[] arr = ids.split(",");
        Integer result=0;
        for (int a=0;a<arr.length;a++){
            result += ls.deleteById(Integer.parseInt(arr[a]));
        }
        if (result==0){
            return HZDLJsonResult.DELETE_ERROR;
        }else {
            return  HZDLJsonResult.DELETE_SUCCESS;
        }
    }



}
